package com.qianyucc.blog.global;

import com.alibaba.fastjson.*;
import com.qianyucc.blog.mapper.*;
import com.qianyucc.blog.model.entity.*;
import com.qianyucc.blog.model.vo.*;
import com.qianyucc.blog.service.*;
import com.qianyucc.blog.utils.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.boot.*;
import org.springframework.data.redis.core.*;
import org.springframework.stereotype.*;

import java.util.*;

/**
 * @author lijing
 * @date 2019-10-14 11:52
 * @description SpringBoot项目启动之后的初始化操作
 */
@Component
public class BlogCommandLineRunner implements CommandLineRunner {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private ConfigService configService;

    @Override
    public void run(String... args) {
        List<ArticleDO> articleDOS = articleMapper.findAll();
        List<SimpleArticleVO> hotArticles = Utils.getHotArticles(articleDOS);
        redisTemplate.opsForValue().set("hotArticles", JSON.toJSONString(hotArticles));
        // 初始化博客配置
        configService.initConfig();
    }
}